<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <title>添加记录</title>
    <!-- head 中 -->
    <link href="${ctxStatic}/plugin/jquery-weui/lib/weui.min.css" type="text/css" rel="stylesheet"/>
    <link href="${ctxStatic}/plugin/jquery-weui/css/jquery-weui.css" type="text/css" rel="stylesheet"/>
    <style>
        .top_bar {
            height: 7vh;
            line-height: 7vh;
            position: relative;
            background: #3399fe;
        }
        .top_bar a.back_history {
            position: absolute;
            left: 10px;
            top: 8px;
            height: 30px;
        }
        .top_bar h2 {
            color: #fff;
            font-size: 18px;
            font-weight:400;
            /*margin-left: 10px;*/
            text-align: center;
        }
        .top_bar a.finish {
            position: absolute;
            right: 10px;
            top: 1px;
            color: #fff;
        }
        .weui-cell{
            font-size: 16px;
        }
    </style>
</head>
<body ontouchstart ng-app="config" ng-controller="configCtrl" ng-init="init()">
<div class="top_bar txt_center f18">
    <h2>新增记录</h2>
</div>
<div id="chooseCus" class='weui-popup__container'>
    <div class="weui-popup__overlay"></div>
    <div class="weui-popup__modal">
        <div class="button_sp_area" style="margin-left: 20px;margin-bottom: -30px;">
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" id="confirmCustomer" >确定</a>
            <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_default close-popup" >关闭</a>
        </div>
        <article class="weui-article" style="margin-top: -10px;">

            <div class="weui-search-bar" id="searchBar" style="width: 100%;height: 43px;">
                <form class="weui-search-bar__form" action="#">
                    <div class="weui-search-bar__box">
                        <i class="weui-icon-search"></i>
                        <input type="search" class="weui-search-bar__input" id="taksName" placeholder="搜索" required="">
                        <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
                    </div>
                    <label class="weui-search-bar__label" id="searchText" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1);">
                        <i class="weui-icon-search"></i>
                        <span>搜索</span>
                    </label>
                </form>
                <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel" ng-click="getProjectList()">确定</a>
            </div>

            <%--<h1>大标题</h1>--%>
            <div class="weui-cells__title">请选择任务</div>
            <div class="weui-cells weui-cells_radio">
                <label class="weui-cell weui-check__label" ng-repeat="x in projectList">
                    <div class="weui-cell__bd" >
                        <input type="radio" class="weui-check" name="project" value="{{x.id}}" text="{{x.taksName}}">{{x.taksName}}
                        <span class="weui-icon-checked" style="float: right;" ></span>
                    </div>
                    <%--<div class="weui-cell__ft">
                        <span class="weui-icon-checked"></span>
                    </div>--%>
                </label>
                <%--<a href="javascript:void(0);" class="weui-cell weui-cell_link">
                    <div class="weui-cell__bd">添加更多</div>
                </a>--%>
            </div>
        </article>

    </div>
</div>
<form id="recordForm">
    <%--<div class="weui-cells">--%>
        <%--<div class="weui-cells__title">新增记录</div>--%>
        <div class="weui-cell ">
            <div class="weui-cell__bd"><label class="weui-label">任务名称</label></div>
            <div class="weui-cell__bd">
            </div>
            <div class="weui-cell__ft">
                <a href="javascript:void(0);" class=" weui-cell_link" ng-click="chooseProject()" >
                    <div class="weui-cell__bd">+点击选择</div>
                </a>
            </div>
        </div>
        <div class="weui-cells" style="margin-top: 0px;" ng-if="project.id!=null">
            <div class="weui-cell">
                <%--<div class="weui-cell__hd" onclick="deleteCustomer()">
                    <img src="" alt="" style="width:20px;margin-right:5px;display:block">
                </div>--%>
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{project.name}}</p>
                </div>
            </div>
        </div>
        <%--<div class="weui-cells" style="margin-top: 0px;" >
            <div class="weui-cell" ng-show="project!=null">
                &lt;%&ndash;<div class="weui-cell__hd" onclick="deleteFriend()">
                    <img src="" alt="" style="width:20px;margin-right:5px;display:block"></div>&ndash;%&gt;
                <div class="weui-cell__bd">
                    <p style="font-size: 15px; margin-left: 20px;">{{project.name}}</p>
                </div>
            </div>
        </div>--%>
        <div class="weui-cell" style="margin-top: 0px;">
            <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="recordName">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">工作类型</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="workType">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">客户联系人</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="text" name="contacts">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">沟通事由</label></div>
        </div>
        <div class="weui-cells weui-cells_form" style="margin-top: 0px;">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <textarea class="weui-textarea" rows="3" name="reason"></textarea>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">沟通结果</label></div>
        </div>
        <div class="weui-cells weui-cells_form" style="margin-top: 0px;">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <textarea class="weui-textarea" rows="3" name="result"></textarea>
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">开始时间</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input"  type="text" name="startTime" id="time-start">
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">结束时间</label></div>
            <div class="weui-cell__bd">
                <input class="weui-input"  type="text" name="endTime" id="time-end">
            </div>
        </div>

    <%--</div>--%>
</form>

<div class="weui-btn-area" style="text-align: center;" ng-show="!state">
    <a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary" style="width: 100px;height: 40px;font-size: 15px;margin-left: auto; margin-right: auto;" ng-click="saveRecord()" >保&nbsp;&nbsp;存</a>
</div>
<script src="${ctxStatic}/plugin/jquery/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/angular/angular.js"></script>
<script src="${ctxStatic}/plugin/jquery-validation/1.14.0/jquery.validate.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/jquery-2.1.4.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/js/jquery-weui.js"></script>
<script src="${ctxStatic}/plugin/jquery-weui/lib/fastclick.js"></script>
<script src="https://cdn.bootcss.com/jquery-json/2.6.0/jquery.json.min.js"></script>
<script>
    var app = angular.module('config', []);
    app.controller('configCtrl',function($scope) {
        $scope.init = function(){
            $scope.project = {};

        };

        //选择客户
        $scope.chooseProject=function(){
            $scope.getProjectList();
            $.openPopup("#chooseCus");
        }

        $scope.saveRecord = function(){
            //获取数据
            var params = {};
            var saleRecordList = [];
            var saleRecord = queryInfos("recordForm");
            saleRecordList.push(saleRecord);
            if($scope.project!=null ){
                if($scope.project.id==null){
                    $.toast("请选择任务！","text");
                    return false;
                }
            }else{
                $.toast("请选择任务！","text");
                return false;
            }
            params.id = $scope.project.id;
            params.saleRecordList = saleRecordList;

            //params.saleTask = saleTask;
            $.ajax({
                url:"${ctx}/sale/saleTask/saveRecord",
                async:false,
                type:"POST",
                traditional:true,
                dataType:"JSON",
                contentType:"application/json",
                data:$.toJSON(params),
                success:function(response){
                    if(response.success){
                        $scope.init();
                        window.location.reload();
                    }else{
                        $.toast(response.msg,"text");
                    }
                }
            });
        };

        $scope.getProjectList = function(){
            console.log($("#taksName").val());
            $.ajax({
                url: "${ctx}/sale/saleTask/data",
                async: false,
                data: {"pageSize": 100,"taksName":$("#taksName").val()},
                type: "POST",
                success: function (respon) {
                    $scope.projectList = respon.rows;
                }
            });

        };

        $("#confirmCustomer").click(function(){
            $scope.project = {};
            $scope.project.id=$("input[name='project']:checked").val();
            $scope.project.name=$("input[name='project']:checked").attr("text");
            $scope.$apply();
            console.log($scope.project);

            //关闭遮罩层
            $.closePopup("#chooseCus");
        });


        //时间控件
        $("#time-start").datetimePicker({
            title: '选择时间',
            yearSplit: '-',
            monthSplit: '-',
            dateSplit: ' ',
            times: function () {
                return [  // 自定义的时间
                    {
                        values: (function () {
                            var hours = [];
                            for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                            return hours;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    }/*,
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ''
                    }*/
                ];
            },
            onChange: function (picker, values, displayValues) {
                console.log(values);
            }
        });
        $("#time-end").datetimePicker({
            title: '选择时间',
            yearSplit: '-',
            monthSplit: '-',
            dateSplit: ' ',
            times: function () {
                return [  // 自定义的时间
                    {
                        values: (function () {
                            var hours = [];
                            for (var i=0; i<24; i++) hours.push(i > 9 ? i : '0'+i);
                            return hours;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    }/*,
                    {
                        divider: true,  // 这是一个分隔符
                        content: ':'
                    },
                    {
                        values: (function () {
                            var minutes = [];
                            for (var i=0; i<59; i++) minutes.push(i > 9 ? i : '0'+i);
                            return minutes;
                        })()
                    },
                    {
                        divider: true,  // 这是一个分隔符
                        content: ''
                    }*/
                ];
            },
            onChange: function (picker, values, displayValues) {
                console.log(values);
            }
        });

        var queryInfos = function (formId) {
            var d = {};
            var t = $('#'+formId).serializeArray();
            $.each(t, function() {
                if(this.value!=""&&this.value!=null&this.value!=undefined){
                    if(this.value.indexOf("number:")>=0){
                        d[this.name] = this.value.split("number:")[1];
                    }else {
                        d[this.name] = this.value;
                    }
                }
            });
            return d;
        }

    });

    //选择客户
    $(function () {
        FastClick.attach(document.body);
    });
    $(document).on("open", ".weui-popup-modal", function () {
        console.log("open popup");
    }).on("close", ".weui-popup-modal", function () {
        console.log("close popup");
    });


</script>
</body>
</html>
